package com.ctshk.sapp.system.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.rpc.system.req.MainDataRowDataReq;
import com.ctshk.rpc.system.service.IMainDataFieldDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;

/**
 * <p>
 * 字段数据 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2020-12-29
 */
@Api(value="主数据表字段数据", tags="主数据表字段数据")
@RestController
@RequestMapping("/main/data/field/data")
public class MainDataFieldDataController extends BaseController {

    /**
     * 字段数据服务
     */
    @DubboReference
    private IMainDataFieldDataService mainDataFieldDataService;

    @ApiOperation(value="新增主数据字段数据", notes="新增主数据字段数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "新增主数据字段数据", operDesc = "新增主数据字段数据")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid MainDataRowDataReq mainDataRowDataReq) {
        mainDataFieldDataService.add(mainDataRowDataReq, getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value="修改主数据字段数据", notes="修改主数据字段数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "修改主数据字段数据", operDesc = "修改主数据字段数据")
    @PostMapping("/update-field")
    public Result updateField(@RequestBody @Valid MainDataRowDataReq mainDataRowDataReq) {
        mainDataFieldDataService.updateField(mainDataRowDataReq, getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value="删除主数据字段数据", notes="删除主数据字段数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.DELETE, operTitle = "删除主数据字段数据", operDesc = "删除主数据字段数据")
    @GetMapping("/delete/row/{id}")
    public Result deleteRow(@PathVariable Long id) {
        mainDataFieldDataService.deleteRow(id, getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value="禁用主数据字段数据", notes="禁用主数据字段数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "禁用主数据字段数据", operDesc = "禁用主数据字段数据")
    @GetMapping("/update/status/{id}")
    public Result updateStatus(@PathVariable Long id) {
        mainDataFieldDataService.updateStatus(id, getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value="查询行数据", notes="查询行数据")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询行数据", operDesc = "查询行数据")
    @GetMapping("/query/row/{id}")
    public Result queryRow(@PathVariable Long id) {
        return Result.success(mainDataFieldDataService.queryRow(id));
    }

    @ApiOperation(value="查询字段值", notes="查询字段值")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询行数据", operDesc = "查询行数据")
    @GetMapping("/query/field/data/{id}")
    public Result queryFieldData(@PathVariable Long id) {
        return Result.success(mainDataFieldDataService.queryFieldData(id));
    }

}
